package com.fc.campusapplicationsystem.service;

import com.fc.campusapplicationsystem.mapper.ServicemanMapper;
import com.fc.campusapplicationsystem.model.Serviceman;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 贺哲
 * @2020-02-29 15:17
 */
@Service
public class ServicemanServiceImpl implements ServicemanService {
    @Autowired
    ServicemanMapper servicemanMapper;

    @Override
    public Serviceman servicemanLogin(String username, String password) {
        return servicemanMapper.selectOne(new Serviceman().
                setServiceName(username).
                setServicePassword(password));
    }

    @Override
    public List<Serviceman> list() {
        return servicemanMapper.selectAll();
    }

    @Override
    public Integer add(Serviceman serviceman) {
        return servicemanMapper.insertSelective(serviceman);
    }

    @Override
    public Integer delete(Integer id) {
        return servicemanMapper.deleteByPrimaryKey(id);
    }

    @Override
    public Serviceman get(int serviceId) {
        return servicemanMapper.selectOne(new Serviceman().setId(serviceId));
    }

    @Override
    public Integer update(Serviceman serviceman) {
        return servicemanMapper.updateByPrimaryKey(serviceman);
    }

    @Override
    public boolean checkUsername(Serviceman serviceman) {
        List<Serviceman> servicemanList = servicemanMapper.selectAll();
        for (Serviceman s : servicemanList) {
            if (s.getServiceName().equals(serviceman.getServiceName())){
                return false;
            }
        }
        return true;
    }
}
